home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / e / amigae33a.lha / E_v3.3a / Src.lha / Src / Various / breukfind.e < prev    next >
Text File  |  1996-11-04  |  806b  |  36 lines

  1. /* find breuk
  2.  
  3. try: 0.14159   -> 1/7 (22/7 = pi)
  4. try: 0.618034  -> fibonacci
  5. try: 0.1234568 -> 10/81
  6.  
  7. */
  8.  
  9. PROC main()
  10.   DEF br[20]:STRING,b,max=1,a,best=2.0,bst,bsta,d,s[20]:STRING,t[20]:STRING,u[20]:STRING
  11.   b:=RealVal(arg)
  12.   WriteF('Ctrl-C to stop searching for \s ...\n',RealF(s,b,7))
  13.   WHILE CtrlC()=FALSE
  14.     bst:=2.0
  15.     FOR a:=0 TO max
  16.       d:=dist(a!/(max!),b)
  17.       IF !d<bst
  18.         bst:=d
  19.         bsta:=a
  20.       ENDIF
  21.     ENDFOR
  22.     d:=dist(bsta!/(max!),b)
  23.     IF !d<best
  24.       best:=d
  25.       WriteF('best sofar: \d\t/ \d,\tdistance \s .. \s = \s\n',bsta,max,RealF(s,b,7),RealF(t,bsta!/(max!),7),RealF(u,best,7))
  26.       IF !best=0.0
  27.         WriteF('best possible reached...\n')
  28.         RETURN
  29.       ENDIF
  30.     ENDIF
  31.     max++
  32.   ENDWHILE
  33. ENDPROC
  34.  
  35. PROC dist(a,b) IS Abs(!a-b*10000000.0!)!/10000000.0
  36.